﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using HK2009.BusinessFacade;
using HK2009.EntityManage;
using HK2009.Common;
using HK2009.EntityQuery;

namespace HK2009.BusinessFacadeHandler
{
    public class SyPlaceHandler : ISyPlaceHandler
    {
        DataBase db = new DataBase();
        Sy_PlaceManage placeManager = new Sy_PlaceManage();

        /// <summary>
        /// 根据sql语句同参数获取地点资料列表
        /// </summary>
        /// <param name="sqlStr"></param>
        /// <param name="parms"></param>
        /// <returns></returns>
        public DataTable GetList(string sqlStr, SqlParameter[] parms)
        {
            return db.RunSqlTab(sqlStr, parms);
        }

        /// <summary>
        /// 获取所有地点资料
        /// </summary>
        /// <returns></returns>
        public DataTable GetList()
        {
            SqlParameter[] parms = new SqlParameter[1];
            parms[0] = new SqlParameter("@Status", "1");
            return placeManager.GetSy_PlaceList(" Status=@Status", parms);  
        }

        /// <summary>
        /// 根据ID删除记录
        /// </summary>
        /// <param name="userID"></param>
        /// <returns></returns>
        public bool DeleteByID(int userID)
        {
            return placeManager.DeleteSy_Place(userID);
        }


        /// <summary>
        /// 根据ID获取地点信息
        /// </summary>
        /// <param name="userID"></param>
        /// <returns></returns>
        public Sy_PlaceQuery GetPlaceByID(int pkid)
        {
            return placeManager.GetSy_PlaceQuery(pkid);
        }


        /// <summary>
        ///  更改地点信息
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public bool UpdatePlace(Sy_PlaceQuery query)
        {
            return placeManager.UpdateSy_Place(query);
        }


        /// <summary>
        /// 添加地点资料
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public bool AddPlace(Sy_PlaceQuery query)
        {
            return placeManager.InsertSy_Place(query);
        }

        public int GetPlaceIDByName(string name)
        {
            int id = 0;
            SqlParameter[] parms = new SqlParameter[3];
            parms[0] = new SqlParameter("@Name", name);
            parms[1] = new SqlParameter("@HKName", name);
            parms[2] = new SqlParameter("@ENGName", name);

            DataTable dt = placeManager.GetSy_PlaceList(" Name=@Name or HKName=@HKName or ENGName=@ENGName", parms);
            if (dt != null && dt.Rows.Count > 0)
            {
                id = int.Parse(dt.Rows[0]["PKID"].ToString());
            }
            return id;     
        }
    }
}